package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.enterprise.EpHotIpEntity;
import com.sgb.kjwl.utils.DisplayUtil;
import com.sgb.kjwl.utils.TextSizeUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class EpDealAdapter extends BaseRecycleAdapter<EpHotIpEntity> {
    ImageView roundImageView;
    TextView tv_title_hot;
    TextView tv_price_hot;
    TextView tv_time_hot;
    TextView tv_label_user, tv_lable_team, tv_label_hot, tvlabel_js;
    private Context context;
    private int position = 0;
    private TextView mLogoViewText;

    public EpDealAdapter(Context context, List<EpHotIpEntity> datas) {
        super(context, R.layout.item_enterprise_remenjiaoyi, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, EpHotIpEntity epHotIpEntity) {
        holder.setBinding(BR.viewModel, epHotIpEntity);
        roundImageView = holder.getItem().findViewById(R.id.logo_view);
        mLogoViewText = holder.getItem().findViewById(R.id.logo_view_text);
        tv_title_hot = holder.getItem().findViewById(R.id.title_view);
        tv_price_hot = holder.getItem().findViewById(R.id.price_view);
        tv_time_hot = holder.getItem().findViewById(R.id.tv_time);
        tv_lable_team = holder.getItem().findViewById(R.id.tv_lable_team);
        tv_label_user = holder.getItem().findViewById(R.id.tv_label_user);
        tv_label_hot = holder.getItem().findViewById(R.id.tv_label_hot);
        tvlabel_js = holder.getItem().findViewById(R.id.tvlabel_js);
        if (epHotIpEntity != null) {
            if (epHotIpEntity.getImg() != null && !epHotIpEntity.getImg().equals("")) {
                roundImageView.setVisibility(View.VISIBLE);
                mLogoViewText.setVisibility(View.GONE);
                Glide.with(context).load(epHotIpEntity.getImg()).into(roundImageView);
            } else if (position == 0) {
                roundImageView.setVisibility(View.GONE);
                mLogoViewText.setVisibility(View.VISIBLE);
                if (epHotIpEntity.getName().length() == 1){
                    mLogoViewText.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
                }else {
                    mLogoViewText.setTextSize(TypedValue.COMPLEX_UNIT_SP,(Math.max((20 - 2 * (epHotIpEntity.getName().length() / 2)), 10)));
                }
                mLogoViewText.setTextColor(Color.parseColor("#B79255"));
                mLogoViewText.setText(TextSizeUtils.singleTextLine(DisplayUtil.dip2px(context,65),mLogoViewText.getTextSize(),epHotIpEntity.getName()));
                roundImageView.setImageResource(R.mipmap.morentu_homesb);
            } else if (position == 1) {
                roundImageView.setVisibility(View.VISIBLE);
                mLogoViewText.setVisibility(View.GONE);
                roundImageView.setImageResource(R.mipmap.morentu_homesb);
            } else if (position == 2) {
                roundImageView.setVisibility(View.VISIBLE);
                mLogoViewText.setVisibility(View.GONE);
                switch (epHotIpEntity.getCategoryName()){
                    case "发明专利":
                        Glide.with(context).load(R.mipmap.qiyefuwu_module_famingzhuanli_for_patent_publish).into(roundImageView);
                        break;
                    case "实用新型":
                        Glide.with(context).load(R.mipmap.shiyongxinxing_patent_publish).into(roundImageView);
                        break;
                    case "外观设计":
                        Glide.with(context).load(R.mipmap.waiguansheji_patent_publish).into(roundImageView);
                        break;
                }
            }
            tv_title_hot.setText("【" + epHotIpEntity.getCategoryName() + "】" + epHotIpEntity.getName());
            tv_time_hot.setText(DateUtils.timestampTo13Date3(epHotIpEntity.getCreateTime()));

            if (!TextUtils.isEmpty(epHotIpEntity.getpublishTypeString())) {

                if (epHotIpEntity.getPublishType() > 1) {
                    tv_label_user.setVisibility(View.GONE);
                    tv_lable_team.setVisibility(View.VISIBLE);
                    tv_lable_team.setText(epHotIpEntity.getpublishTypeString());
                } else if(epHotIpEntity.getPublishType()>-1){
                    tv_lable_team.setVisibility(View.GONE);
                    tv_label_user.setVisibility(View.VISIBLE);
                    tv_label_user.setText(epHotIpEntity.getpublishTypeString());
                }else{
                    tv_lable_team.setVisibility(View.GONE);
                    tv_label_user.setVisibility(View.GONE);
                }
            }else{
                tv_lable_team.setVisibility(View.GONE);
                tv_label_user.setVisibility(View.GONE);
            }
            tv_label_hot.setVisibility(View.GONE);
            tvlabel_js.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(epHotIpEntity.getLabel())) {

                if(epHotIpEntity.getLabel().indexOf("1")>-1){
                    tv_label_hot.setVisibility(View.VISIBLE);
                }
                if(epHotIpEntity.getLabel().indexOf("2")>-1){
                    tvlabel_js.setVisibility(View.VISIBLE);
                }

            }


        }


    }

    public void setSelected(int position) {
        this.position = position;
    }
}
